package org.noote.libs.assistant.analyse;

import java.util.ArrayList;
import java.util.Random;

public class Liste_Elements extends ArrayList<Element> {

	private static final long serialVersionUID = -877578084207135121L;

	@Override
	public String toString()
	{
		String elFormat="";
		for(Element e : this)
		{
			if(elFormat.length()>0) elFormat += " ";
			elFormat += e.toString();
		}
		return elFormat;
	}

	public void generate(String[] sStrings) {
		for(String s : sStrings)
		{
			add(new Element(new Element_Mot(s)));
		}
	}
	
	public boolean find(Element element)
	{
		for(Element e : this)
		{
			if(e.kindOf(element))
			{
				return true;
			}
		}
		return false;
	}
	public boolean find(String element)
	{
		for(Element e : this)
		{
			if(e.kindOf(element))
			{
				return true;
			}
		}
		return false;
	}
	public boolean findOne(String[] elements)
	{
		for(String toFind : elements)
		{
			for(Element e : this)
			{
				if(e.kindOf(toFind))
				{
					return true;
				}
			}
		}
		return false;
	}
	public boolean findOne(Liste_Elements elements)
	{
		for(Element toFind : elements)
		{
			for(Element e : this)
			{
				if(e.kindOf(toFind))
				{
					return true;
				}
			}
		}
		return false;
	}
	public int getIndexOfFirst(Liste_Elements elements)
	{
		for(Element toFind : elements)
		{
			int iIndex = 0;
			for(Element e : this)
			{
				if(e.kindOf(toFind))
				{
					return iIndex;
				}
				iIndex++;
			}
		}
		return -1;
	}
	public int getIndexOfFirst(String[] elements)
	{
		for(String toFind : elements)
		{
			int iIndex = 0;
			for(Element e : this)
			{
				if(e.kindOf(toFind))
				{
					return iIndex;
				}
				iIndex++;
			}
		}
		return -1;
	}
	public boolean findAll(Liste_Elements elements)
	{
		for(Element toFind : elements)
		{
			boolean found = false;
			for(Element e : this)
			{
				if(e.kindOf(toFind))
				{
					found = true;
					break;
				}
			}
			if(!found) return false;
		}
		return true;
	}

	public boolean findAll(String[] sStrings) {
		for(String toFind : sStrings)
		{
			boolean found = false;
			for(Element e : this)
			{
				if(e.kindOf(toFind))
				{
					found = true;
					break;
				}
			}
			if(!found) return false;
		}
		return true;
	}

	public Element getOneOfList(Random rRand) {
		return get(rRand.nextInt(this.size()));
	}
}
